/*
 * @(#)ListWorkflowMonitoringGroupAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.form.FormConstant;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.web.AbstractListAction;
import com.dcivision.framework.web.AbstractSearchForm;
import com.dcivision.workflow.bean.WorkflowGroup;
import com.dcivision.workflow.dao.WorkflowGroupDAObject;

/**
 * <p>Class Name:       ListWorkflowMonitoringGroupAction.java    </p>
 * <p>Description:      The list action class for ListWorkflowMonitoringGroup.jsp</p>
 * @author           Angus Shiu
 * @company          DCIVision Limited
 * @creation date    11/12/2003
 * @version          $Revision: 1.7.26.1 $
 */

public class ListWorkflowMonitoringGroupAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.7.26.1 $";

  public static final String VAR_ACTIVE_RECORD_LIST = "listActiveRecord";

  /** Creates a new instance of ListWorkflowMonitoringGroupAction */
  public ListWorkflowMonitoringGroupAction() {
    super();
    this.setListName("workflowMonitoringQueryList");
    this.setListFunctionName("getAllAccessibleList");
  }

  public String getFunctionCode() {
    return(SystemFunctionConstant.WORKFLOW_MONITOR);
  }

  public String getMajorDAOClassName() {
    return("com.dcivision.workflow.dao.WorkflowQueryRecordDAObject");
  }

  /**  Method getListData() - retrieve the appropriate item list for current page
   *
   *  @param      mapping               ActionMapping from struts
   *  @param      form                  ActionForm from struts
   *  @param      request               HttpServletReuqest
   *  @param      respond               HttpServletRespond
   *  @return     void
   *  @throws     ApplicationException  Throws Exception if cannot get the list data from DAO object
   */
  public void getListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    super.getListData(mapping, form, request, response);

    WorkflowGroupDAObject workflowGroupDAO = (WorkflowGroupDAObject) this
       .getDAObjectByClassName(request, "com.dcivision.workflow.dao.WorkflowGroupDAObject");
    List resultList = workflowGroupDAO.getAccessibleMonitoringList();
    request.setAttribute(VAR_ACTIVE_RECORD_LIST, this.getWorkflowGroup(request, resultList));
  }

  /**
   * get workflowGroup string array 
   * @param request
   * @return String[][]
   * @throws ApplicationException
   */
  private String[][] getWorkflowGroup(HttpServletRequest request, List resultList) {
    String[][] workflowGroupArr = null;
    workflowGroupArr = new String[resultList.size() + 2][2];
    workflowGroupArr[0][0] = MessageResourcesFactory.getMessage(this.getLocale(request),
        "common.options.select_menu.select_one");
    workflowGroupArr[0][1] = "";
    workflowGroupArr[1][0] = MessageResourcesFactory.getMessage(this.getLocale(request),
        "common.options.select_menu.query_with_no_workflow_group");
    workflowGroupArr[1][1] = FormConstant.BAND_NONEWORKFLOWRECORDID;
    
    for (int i = 0; i < resultList.size(); i++) {
      WorkflowGroup workflowGroup = (WorkflowGroup)resultList.get(i);
      workflowGroupArr[i + 2][0] = workflowGroup.getGroupName();
      workflowGroupArr[i + 2][1] = workflowGroup.getID().toString();
    }
    
    return workflowGroupArr;
  }
}